<template>
    <nav id="bottom-tab-menu">
        <div class="menu-item">
            <a v-bind:class="{'active':$route.path=='/'}" href="#/">
                <i class="iconfont"></i>
                <div class="name">首页</div>
            </a>
        </div>
        <div class="menu-item">
            <a v-bind:class="{'active':$route.path=='/search'}" href="#/search">
                <i class="iconfont"></i>
                <div class="name">搜索</div>
            </a>
        </div>
        <div class="menu-item hide">
            <a v-bind:class="{'active':$route.path.indexOf('/category')>-1}" href="#/category">
                <i class="iconfont"></i>
                <div class="name">分类</div>
            </a>
        </div>
        <div class="menu-item cart">
            <a v-bind:class="{'active':$route.path=='/cart'}" href="#/cart">
                <i class="iconfont">
                    <span v-show="has_cart" class="cart-total" style=""></span>
                </i>
                <div class="name">购物车</div>
            </a>
        </div>
        <div class="menu-item">
            <a v-bind:class="{'active':$route.path=='/account'}" href="#/account">
                <i class="iconfont"></i>
                <div class="name">我的</div>
            </a>
        </div>
    </nav>
</template>

<script>
    export default {

        data:function(){
            return {

                has_cart:0
            }
        },
        methods:{

            cart_change:function( data ){

                this.get_cart_list();
            },

            get_cart_list:function( tag ){

                var t = this;
                var url = this.config.app_url + '&r=cart.index';
                this.axios.get( url )
                    .then(function (res) {

                        t.has_cart = res.data.list.length > 0;

                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },

        },

        watch:{



        },

        created:function(){

            this.bus.$on('cart-change', this.cart_change );
            this.get_cart_list();

        }

    }
</script>